home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / ripdump.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  1KB  |  82 lines

  1. /* RIP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include "global.h"
  5. #include "config.h"
  6. #ifdef RIP
  7. #include "mbuf.h"
  8. #include "netuser.h"
  9. #include "timer.h"
  10. #include "rip.h"
  11. #include "trace.h"
  12.  
  13. void
  14. #ifdef MONITOR
  15. rip_dump(fp,bpp,mon)
  16. int mon;
  17. #else
  18. rip_dump(fp,bpp)
  19. #endif
  20. FILE *fp;
  21. struct mbuf **bpp;
  22. {
  23.     struct rip_route entry;
  24.     int i;
  25.     int cmd,version;
  26.     int16 len;
  27.     
  28. #ifdef MONITOR
  29.     if (mon)
  30.         fprintf(fp, "RIP ");
  31.     else
  32. #endif
  33.     fprintf(fp,"RIP: ");
  34.     cmd = PULLCHAR(bpp);
  35.     version = PULLCHAR(bpp);
  36.     switch(cmd){
  37.     case RIPCMD_REQUEST:
  38.         fprintf(fp,"REQUEST");
  39.         break;
  40.     case RIPCMD_RESPONSE:
  41.         fprintf(fp,"RESPONSE");
  42.         break;
  43.     default:
  44. #ifdef MONITOR
  45.         if (!mon)
  46. #endif
  47.         fprintf(fp," cmd %u",cmd);
  48.         break;
  49.     }
  50.  
  51.     pull16(bpp);    /* remove one word of padding */
  52.  
  53.     len = len_p(*bpp);
  54. #ifdef MONITOR
  55.     if (mon)
  56.         fprintf(fp, "\n");
  57.     else
  58. #endif
  59.     fprintf(fp," vers %u entries %u:\n",version,len / RIPROUTE);
  60.  
  61.     i = 0;
  62.     while(len >= RIPROUTE){
  63.         /* Pull an entry off the packet */
  64.         pullentry(&entry,bpp);
  65.         len -= RIPROUTE;
  66.  
  67.         if(entry.addr_fam != RIP_IPFAM) {
  68.             /* Skip non-IP addresses */
  69.             continue;
  70.         }
  71.         fprintf(fp,"%-16s%-3u ",inet_ntoa(entry.target),entry.metric);
  72.         if((++i % 3) == 0){
  73.             fprintf(fp,"\n");
  74.         }
  75.     }
  76.     if((i % 3) != 0)
  77.         fprintf(fp,"\n");
  78. }
  79. #endif /* RIP */
  80.  
  81.  
  82.